<template>
  <div>
    <!-- <h1>历史搜索</h1> -->
    <div
      class="his-hot"
      v-show="isShowHistory"
    >
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon
          name="delete-o"
          @click="clearHistory"
        />
      </div>
      <div class="bd">
        <van-tag
          v-for="(list, index) in historyListData"
          :key="index"
          @click="tagClick(list)"
          plain
          type="default"
        >{{ list }}</van-tag>
      </div>
    </div>

    <!-- 热门搜索 -->
    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
        <!-- <van-icon name="delete-o" /> -->
      </div>
      <div class="bd">
        <van-tag
          v-for="(item, i) in hotListData"
          :key="i"
          :class="item.is_hot ? 'red' : ''"
          @click="tagClick(item.keyword)"
          plain
          type="default"
        >{{ item.keyword }}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistoryData } from "@/request/api.js";
export default {
  data() {
    return {
      isShowHistory: true,
    };
  },
  methods: {
    tagClick(val) {
      // console.log("val的值：", val);
      this.$emit("tagClick", val);
    },
    clearHistory() {
      ClearHistoryData().then((res) => {
        if (res.errno == 0) {
          console.log(res);
          // alert("删除成功");
          // 删除提示
          this.$toast.success("删除成功");
          setTimeout(() => {
            // 隐藏历史搜索盒子
            this.isShowHistory = false;
          }, 1000);
        }
      });
    },
  },
  props: ["historyListData", "hotListData"],
};
</script>

<style lang="less" scoped>
.his-hot {
  background-color: white;
  padding: 0.1rem;
  margin-bottom: 0.6rem;
  // margin-top: 0.2rem;
  .hd {
    display: flex;
    justify-content: space-between;
    font-size: 1.4rem;
    margin-bottom: 0.3rem;
    h4 {
      font-size: 1rem;
      margin-top: 0.2rem;
    }
  }
  .van-tag {
    margin-right: 0.2rem;
    padding: 0.2rem;
    margin-bottom: 0.5rem;
  }
  .red {
    color: darkred;
  }
}
</style>
